import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 23735
 * Date: 2023-09-18
 * Time: 23:23
 */
public class Solution {

    /**
     *  简单的题目怎么描述就怎么做
     */
    public int rangeSum(int[] nums, int n, int left, int right) {
        int MODULO = 1000000007;
        int len = nums.length;
        int newLen = len*(len+1)/2;
        int[] arr = new int[newLen];
        int count = 0;
        for (int i = 0;i < len;i++) {
            int sum = 0;
            for (int j = i;j < len;j++) {
                sum += nums[j];
                arr[count++] = sum;
            }
        }
        Arrays.sort(arr);
        long res = 0;
        // 注意下标是从 1 开始的
        for (int i = left-1;i < right;i++) {
            res += arr[i];
        }
        return (int)(res % (MODULO));
    }
}